import 'package:base_flutter/base_flutter.dart';
import 'package:fan_da_app/account/account_manager.dart';
import 'package:fan_da_app/account/user_manager.dart';
import 'package:fan_da_app/res/drawables.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../view_model/main_view_model.dart';
import 'circle_home_page.dart';
import 'home_main_page.dart';

class MainPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _MainState();
}

class _MainState extends BaseMvvmState<MainViewModel, MainPage> {
  var index = 0;

  @override
  Widget? buildLoadingContentView() {
    return Stack(
      children: [
        viewList[index].setLocation(left: 0, top: 0, right: 0, bottom: 0),
        bottomTab().setLocation(bottom: 28, left: 28, right: 28)
      ],
    );
  }

  var viewList = [
    AccountManager.instance.hasCircle ? HomeMainPage() : CircleHomePage(),
    CircleHomePage()
  ];

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: loadingContentWidget,

    );
  }

  Widget bottomTab() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Stack(
              clipBehavior: Clip.none,
              children: [
                if (index == 0)
                  Container(
                    width: 10,
                    height: 10,
                    decoration:
                        BoxDecoration(color: mainColor, shape: BoxShape.circle),
                  ).setLocation(top: 4, right: 2),
                SvgPicture.asset(
                  icon_home_order,
                  width: 28,
                  height: 28,
                  colorFilter: ColorFilter.mode(
                      index == 0 ? Colors.black : defaultGray, BlendMode.srcIn),
                ),
              ],
            ).addToContainer(width: 28, height: 28),
            SizedBox(
              height: 2,
            ),
            CommonText('首页',
                textSize: 12,
                textColor: index == 0 ? Colors.black : defaultGray)
          ],
        ).onTap(() {
          setState(() {
            index = 0;
          });
        }),
        Icon(Icons.add).addToContainer(
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: mainColor,
            ),
            width: 40,
            height: 40),
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Stack(
              clipBehavior: Clip.none,
              children: [
                if (index == 1)
                  Container(
                    width: 10,
                    height: 10,
                    decoration:
                        BoxDecoration(color: mainColor, shape: BoxShape.circle),
                  ).setLocation(top: 4, right: 2),
                SvgPicture.asset(icon_home_mine,
                    width: 28,
                    height: 28,
                    colorFilter: ColorFilter.mode(
                        index == 1 ? Colors.black : defaultGray,
                        BlendMode.srcIn)),
              ],
            ).addToContainer(width: 28, height: 28),
            SizedBox(
              height: 2,
            ),
            CommonText('我的',
                textSize: 12,
                textColor: index == 1 ? Colors.black : defaultGray)
          ],
        ).onTap(() {
          setState(() {
            index = 1;
          });
        }),
      ],
    ).addToContainer(
        decoration: BoxDecoration(
            color: Colors.white.withOpacity(0.6),
            borderRadius: 40.borderRadius),
        height: 60);
  }

  @override
  MainViewModel createViewModel() {
    return MainViewModel(context);
  }

  @override
  void onRetryClick() {}
}
